package com.ruoyi.core.config;

import com.gitee.deeround.jdbchelper.DbAction;
import com.gitee.deeround.jdbchelper.DbActionConfig;
import com.gitee.deeround.jdbchelper.impl.DbActionImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;

@Configuration
public class JdbchelperConfig {

    @Autowired
    private GlobalProperties globalProperties;

    @SuppressWarnings("all")
    @Bean
    public DbAction dbAction(JdbcTemplate jdbcTemplate) {

        GlobalProperties.Db db = globalProperties.getDb();

        //默认自动识别数据库类型，如果只使用一种数据库，可以指定数据库类型
        DbActionConfig.build().setDbType(db.getDbType()).setReadonly(db.getReadonly()).setWriteMaxNum(db.getWriteMaxNum());

        return new DbActionImpl(jdbcTemplate);
    }
}
